package com.service;

import com.achievement.domain.entity.PatentEntity;
import com.achievement.domain.param.*;
import com.achievement.domain.vo.*;
import com.achievement.service.impl.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.core.domain.entity.SysUser;
import com.common.core.domain.model.LoginUser;
import com.common.utils.SecurityUtils;
import com.entity.PersonEntity;
import com.base.entity.bo.SciencePersonBo;
import com.base.entity.vo.SciencePersonVo;
import com.base.mapper.SciencePersonMapper;
import com.common.core.page.PageDomain;
import com.feemanage.domain.bo.BizCwIncomeClaimBo;
import com.feemanage.domain.vo.BizCwIncomeClaimVo;
import com.feemanage.service.impl.cWIncomeClaimServiceImpl;
import com.project.domain.bo.ProjectInfoBo;
import com.project.domain.vo.ProListInfoVo;
import com.project.service.impl.ProjectInitServiceImpl;
import com.system.service.ISysRoleService;
import com.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class PersonService {
    @Autowired
    SciencePersonMapper sciencePersonMapper;

    @Autowired
    ProjectInitServiceImpl projectInitService;

    @Autowired
    ISysUserService iSysUserService;

    @Autowired
    ISysRoleService iSysRoleService;

    @Autowired
    StandardServiceImpl standardService;

    @Autowired
    cWIncomeClaimServiceImpl cWIncomeClaimService;

    @Autowired
    MedicineServiceImpl medicineService;

    @Autowired
    PatentServiceImpl patentService;

    @Autowired
    CopyRightServiceImpl copyRightService;

    @Autowired
    BreedServiceImpl breedService;

    @Autowired
    ProductTransformServiceImpl productTransformService;

    @Autowired
    ArtProductServiceImpl artProductService;

    @Autowired
    JoinMeetingServiceImpl joinMeetingService;

    @Autowired
    ReportServiceImpl reportService;

    @Autowired
    AppraisalProductServiceImpl appraisalProductService;

    @Autowired
    PaperServiceImpl paperService;

    public PersonEntity personCheck(SciencePersonVo sciencePersonVo) {
        if(sciencePersonVo.getId() == null || sciencePersonVo.getId().isEmpty() ){
            LoginUser loginUser = SecurityUtils.getLoginUser();
            SysUser user = loginUser.getUser();
            sciencePersonVo.setId(user.getUserRealId());
        }
        List<SciencePersonBo> list = sciencePersonMapper.selectPersonDetails(sciencePersonVo);
        //入账
        ProjectInfoBo projectInfoBo=new ProjectInfoBo();
        projectInfoBo.setPageNo(1);
        projectInfoBo.setPageSize(100);
        projectInfoBo.setStartBeginDate(sciencePersonVo.getCreatedate()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                );
        projectInfoBo.setEndBeginDate(sciencePersonVo.getLastdate());
        projectInfoBo.setPersonId(sciencePersonVo.getId());
        projectInfoBo.setProClass("zXProject");
        projectInfoBo.setCheckstatus("2");
        IPage<ProListInfoVo> a=projectInitService.getProList(projectInfoBo,"select");
        projectInfoBo.setProClass("yfContract");
        projectInfoBo.setOrderStr("createdate");
        IPage<ProListInfoVo> b=projectInitService.getProList(projectInfoBo,"select");
        projectInfoBo.setProClass("xJProject");
        projectInfoBo.setOrderStr("createdate");
        IPage<ProListInfoVo> c=projectInitService.getProList(projectInfoBo,"select");

        //到账
        PageDomain pageDomain=new PageDomain();
        pageDomain.setPageNum(1);
        pageDomain.setPageSize(100);
        BizCwIncomeClaimBo claim=new BizCwIncomeClaimBo();
        claim.setChargerId(sciencePersonVo.getId());
        claim.setProjectClass("zXProject");
        claim.setCheckstatus("2");
        IPage<BizCwIncomeClaimVo> list1=cWIncomeClaimService.selectList(pageDomain,claim);
        claim.setProjectClass("yfContract");
        IPage<BizCwIncomeClaimVo> list2=cWIncomeClaimService.selectList(pageDomain,claim);
        claim.setProjectClass("xJProject");
        IPage<BizCwIncomeClaimVo> list3=cWIncomeClaimService.selectList(pageDomain,claim);

        //成果
        StandardParam param=new StandardParam();
        param.setAuthorpids(sciencePersonVo.getId());
        param.setCheckstatus("2");
        param.setPublicDateStart(sciencePersonVo.getCreatedate());
        param.setPublicDateEnd(sciencePersonVo.getLastdate());
        List<StandardVO> list4=standardService.getListByConditions(param);

        PatentParam param1=new PatentParam();
        param1.setAuthorpids(sciencePersonVo.getId());
        param1.setCheckStatus("2");
//        param1.setApplyDateStart(sciencePersonVo.getCreatedate());
//        param1.setApplyDateEnd(sciencePersonVo.getLastdate());
        List<PatentEntity> list5=patentService.getListByConditions(param1);

        MedicineParam param2=new MedicineParam();
        param2.setAuthorpids(sciencePersonVo.getId());
        param2.setCheckstatus("2");
        param2.setAuthorizeDateStart(sciencePersonVo.getCreatedate());
        param2.setAuthorizeDateEnd(sciencePersonVo.getLastdate());
        List<MedicineVO> list6=medicineService.getListByConditions(param2);

        CopyRightParam param3=new CopyRightParam();
        param3.setAuthorpids(sciencePersonVo.getId());
        param3.setCheckstatus("2");
        param3.setPublicationDateStart(sciencePersonVo.getCreatedate());
        param3.setPublicationDateEnd(sciencePersonVo.getLastdate());
        List<CopyRightVO> list7=copyRightService.getListByConditions(param3);

        BreedParam param4=new BreedParam();
        param4.setAuthorpids(sciencePersonVo.getId());
        param4.setCheckstatus("2");
        param4.setAuthorizeDateStart(sciencePersonVo.getCreatedate());
        param4.setAuthorizeDateEnd(sciencePersonVo.getLastdate());
        List<BreedVO> list8=breedService.getListByConditions(param4);

        ProductTransformParam param5=new ProductTransformParam();
        param5.setAuthorpids(sciencePersonVo.getId());
        param5.setCheckstatus("2");
        List<ProductTransformVO> list9=productTransformService.getListByConditions(param5);

        ArtProductParam param6=new ArtProductParam();
        param6.setAuthorpids(sciencePersonVo.getId());
        param6.setCheckstatus("2");
        param6.setPublicationDateStart(sciencePersonVo.getCreatedate());
        param6.setPublicationDateEnd(sciencePersonVo.getLastdate());
        List<ArtProductVO>  list10=artProductService.getListByConditions(param6);

        ReportParam param7=new ReportParam();
        param7.setAuthorpids(sciencePersonVo.getId());
        param7.setCheckstatusList(Collections.singletonList("2"));
        param7.setSubmitDateStart(sciencePersonVo.getCreatedate());
        param7.setSubmitDateEnd(sciencePersonVo.getLastdate());
        List<ReportVO>  list11=reportService.getListByConditions(param7);

        AppraisalProductParam param8=new AppraisalProductParam();
        param8.setAuthorpids(sciencePersonVo.getId());
        param8.setCheckstatusList(Collections.singletonList("2"));
        param8.setAppraisalDateStart(sciencePersonVo.getCreatedate());
        param8.setAppraisalDateEnd(sciencePersonVo.getLastdate());
        List<AppraisalProductVO>  list12=appraisalProductService.getListByConditions(param8);

        PaperParam param9=new PaperParam();
        param9.setAuthorpids(sciencePersonVo.getId());
        param9.setPublishDateStart(sciencePersonVo.getCreatedate());
        param9.setPublishDateEnd(sciencePersonVo.getLastdate());
        List<PaperVO>  list13=paperService.selectByPage(param9);

//        JoinMeetingParam param7=new JoinMeetingParam();
//        param7.setAuthorpids(sciencePersonVo.getId());
//        List<JoinMeetingVO> list11=joinMeetingService.getListByConditions(param6);

        PersonEntity personEntity=new PersonEntity();
        personEntity.setList(list);
        personEntity.setZxxmlx(a.getRecords());
        personEntity.setJzhtqd(b.getRecords());
        personEntity.setXjxmlx(c.getRecords());
        personEntity.setZxxmdz(list1.getRecords());
        personEntity.setYfhtdz(list2.getRecords());
        personEntity.setXjxmdz(list3.getRecords());
        personEntity.setStandard(list4);
        personEntity.setPatent(list5);
        personEntity.setMedicine(list6);
        personEntity.setCopyRight(list7);
        personEntity.setBreed(list8);
        personEntity.setProductTransform(list9);
        personEntity.setArtProduct(list10);
        personEntity.setResearchReport(list11);
        personEntity.setAppraisalProduct(list12);
        personEntity.setPaper(list13);

        return personEntity;
    }
}
